<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建公司</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=yes" name="format-detection" />
    <link href="<%=basepath%>css/index.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/registered.css" rel="stylesheet" type="text/css">
    <script src="<%=basepath%>js/jquery-1.8.3.min.js"></script>
    <script src="<%=basepath%>js/layer/layer.js"></script>
    <script src="<%=basepath%>js/jquery.md5.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
        <div class="header-1">
            <a href="javascript:void(0)" id="join" class="header-2">
                <span id="account" class="account">${empty user.realName ? '您还未登录哦！' : user.realName}</span>&nbsp;&nbsp;<span id="compNickName" class="compNickName">${user.companyNickName}</span>&nbsp;&nbsp;<span id="deptName" class="deptName">${user.departmentName}</span>
            </a>
            <a href="javascript:history.go(-1)" class="back">返回</a>
            <span class="span-num"></span>
        </div>
    </div>
    <div class="content m-top">
        <div class="content2">
            <form method="post" id="myform" action="/wape-web/api/core/centerService">
                <input type="hidden" name="companyType" value="0">
                <div class="content2-3"><input type="text" placeholder="创建公司名称" maxlength="15px" id="companyName" name="companyName"></div>
                <div class="content2-3"><input type="text" placeholder="图片验证码" id="code" maxlength="6px;" class="input-code"><span id="yzm" class="yam" onclick="document.getElementById('yzm').innerHTML = yzm();"></span> </div>
                <div class="content2-3"><input type="text" placeholder="管理员真实姓名" maxlength="10px" id="adminName" name="adminName"></div>
                <!-- <div class="content2-2"><input type="text" placeholder="管理员电话" maxlength="6px" id="sms" class="content2-2-1" name="sms"><input type="button" value="获取短信验证码" id="btn" class="btn"> </div> -->
                <div class="content2-3"><input type="text" placeholder="管理员电话" maxlength="25px" id="adminPhone" name="adminPhone"></div>
                <div class="content2-3"><input type="password" placeholder="设置管理员密码" maxlength="25px" id="adminPwd" name="adminPwd"></div>
                <div class="content2-3"><input type="password" placeholder="确认管理员密码" maxlength="25px" id="again"></div> 
                <div class="content2-4"><input type="checkbox" id="checkbox" checked="checked"><a href="javascript:void(0)" id="protocol">《农商易用户使用协议》</a> </div>
                <input type="hidden" name="serviceCode" value="5001U12" />
                <div class="content2-5"><input type="submit" value="确认申请" class="submit"></div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    /*错误提示*/
    $(function(){
        var error = "${requestScope.returnMsg}";
        if(error != "" && error != "成功!"){
            layer.msg(error,{shadeClose:true,shade:0.1,time:2000});
        }
    });
    /*验证码*/
    var fss=function(){
        var arr = ['A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        $("#yzm").text(str);
    };
    $(function(){
        fss()
    });
    function yzm(){
        var arr = ['A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        return str;
    }
    /*用户协议*/
    $(function(){
        $("#protocol").click(function(){
            layer.open({
                type:2,
                title:"《快来网络用户注册协议》",
                shadeClose:true,
                shade:0.2,
                area:["90%","60%"],
                content:"agreement.html"
            })
        })
    });
    /*获取验证码时间*/
    $(function(){
        var wait=60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value="免费获取验证码";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                            time(o)
                        },
                        1000)
            }
        }
        $("#btn").click(function(){time(this);});
    });
    /*注册*/
    $(function(){
        $("#myform").submit(function(){
        	var join = "${user.companyName}";
            var companyName=$("#companyName").val();
            var code=$("#code").val().toUpperCase();
            var yzm=$("#yzm").text();
            var adminName=$("#adminName").val();
            var adminPhone=$("#adminPhone").val();
            var patrn =/^1[3,5,7,8]\d{9}$/;
            var adminPwd=$("#adminPwd").val();
            var again=$("#again").val();
            //var sms=$("#sms").val();
            var checkbox=$("#checkbox").prop("checked");
            if(join != ""){
            	layer.msg("您已加入公司！",{shadeClose:true,shade:0.1,time:2000});
            	return false;
            }
            else if(companyName == ""){
                layer.msg("请输入公司名",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(code==""){
                layer.msg("请输入验证码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(code.length<4){
                layer.msg("验证码少于4位字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(code.length>4){
                layer.msg("验证码大于于4位字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(code!=yzm){
                layer.msg("验证码错误",{shadeClose:true,shade:0.1,time:2000});
                fss();
                return false;
            }
            else if(adminName==""){
                layer.msg("请输入真实姓名",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(!adminName.match(/^[\u4e00-\u9fa5]{0,}$/)){
                layer.msg("请输入汉字格式姓名",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(adminName.length>8){
                layer.msg("姓名过长",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(adminPhone==""){
                layer.msg("请输入管理员手机号",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(!patrn.test(adminPhone)){
                layer.msg("请输入正确格式手机号",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            /* else if(sms==""){
                layer.msg("请输入短信验证码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            } */
            else if(adminPwd==""){
                layer.msg("请输入密码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(adminPwd.length<6){
                layer.msg("密码不能少于6个字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(adminPwd.length>20){
                layer.msg("密码不能大于20个字符",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            /* else if(!adminPwd.match(/^[a-zA-Z]\w{5,19}$/)){
                layer.msg("密码请以字母开头，只能包含字母、数字和下划线",{shadeClose:true,shade:0.1,time:2000});
                return false;
            } */
            else if(again==""){
                layer.msg("请再次输入密码",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(adminPwd!=again){
                layer.msg("两次密码不一致",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else if(checkbox==""){
                layer.msg("请勾选注册协议",{shadeClose:true,shade:0.1,time:2000});
                return false;
            }
            else{
                var b = $("#adminPwd").val();
                var c = $.md5($.md5($.md5(b)));
                $("#adminPwd").val(c);
                layer.load();
                setTimeout(function(){
                	  layer.closeAll();
                	  layer.msg("网络异常，请重新尝试！",{shadeClose:true,shade:0.1,time:2000});
                	}, 30000);
            }
        })
    });
</script>

</html>
